import os
import pandas as pd
from platform import system


def update_time():
    pass


def case_info(data_path, image_path=None):
    mouse_up_image = []
    if os.path.exists(data_path) and os.path.isfile(data_path):
        record_data = pd.read_csv(data_path, index_col=0)
        # ["点击间隔", "按键类别", "事件类型", "输入数据"]
        all_step = record_data.shape[0]
        for run_step in range(0, record_data.shape[0]):
            press_type = record_data.iloc[run_step, 1]
            event_type = record_data.iloc[run_step, 2]
            # input_data = eval(
            #     record_data.iloc[run_step, 3].replace("", ""))
            input_data = record_data.iloc[run_step, 3]
            if press_type == 'Mouse' and event_type == 'mouse left up':
                next_up = run_step+2
                if next_up < all_step and system() == 'Linux':
                    next_press_type = record_data.iloc[next_up, 1]
                    next_event_type = record_data.iloc[next_up, 2]
                    # next_input_data = eval(
                    #     record_data.iloc[next_up, 3].replace("", ""))
                    next_input_data = record_data.iloc[run_step, 3]
                    if press_type == next_press_type and event_type == next_event_type and input_data == next_input_data:
                        run_step = next_up
                        mouse_up_image.append(str(run_step+1)+".png")
                    else:
                        mouse_up_image.append(str(run_step+1)+".png")
                mouse_up_image.append(str(run_step+1)+".png")

            if press_type == 'Mouse' and event_type == 'mouse right up':
                mouse_up_image.append(str(run_step+1)+".png")
            # if press_type == 'Mouse' and event_type == 'mouse middle up':
            #     mouse_up_image.append(str(run_step+1)+".png")
    else:
        print("数据文件不存在")
    mouse_up_image = list(dict.fromkeys(mouse_up_image))
    if image_path == None:
        current_image = mouse_up_image
    else:
        if os.path.exists(image_path):
            current_image = os.listdir(image_path)
            current_image.sort(key=lambda x: int(x[:-4]))
            print("录制步骤截图:%s,图片总数:" % mouse_up_image,len(mouse_up_image))
            print("运行结果截图:%s,图片总数:" % current_image, len(current_image))
    if current_image == mouse_up_image and current_image and mouse_up_image:
        return mouse_up_image
    else:
        return -1